﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;
using System.Collections.Specialized;
using System.Web.Configuration;

namespace MLY
{
  public class g
  {
    public g() { }

    public static string AppConnectionString
    {
      get
      {
        ConnectionStringSettings conStrSet =
               WebConfigurationManager.ConnectionStrings["MLYConnectionString"];
        return conStrSet.ConnectionString;
      }
    }

    //public static DateTime ParseDate(string DateString)
    //{
    //  if ((DateString == null) || (DateString == string.Empty))
    //  {
    //    return new DateTime(0);
    //  }
    //  else
    //  {
    //    CultureInfo juwishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    //    return DateTime.Parse(DateString, juwishCulture);
    //  }
    //}
    
    //public static DateTime? ParseNDate(string DateString)
    //{
    //  if (string.IsNullOrEmpty(DateString))
    //  {
    //    return null;
    //  }
    //  else
    //  {
    //    CultureInfo juwishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    //    return DateTime.Parse(DateString, juwishCulture);
    //  }
    //}
    
    //public static bool TryParseExactDate(string DateString, out DateTime DateValue)
    //{
    //  CultureInfo juwishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    //  string[] formats = new string[2] { "d/M/yy", "d/M/yyyy" };
    //  return DateTime.TryParseExact(DateString, formats, juwishCulture, DateTimeStyles.None, out DateValue);
    //}

    //public static string FormatDate(DateTime? d)
    //{
    //  if (d == null)
    //  {
    //    return string.Empty;
    //  }
    //  else
    //  {
    //    DateTime dd = (DateTime)d;
    //    return dd.ToString("dd/MM/yyyy");
    //  }
    //}
    
    public static string FormatDecimalAmount(decimal? d)
    {
      if (d == null)
      {
        return string.Empty;
      }
      else
      {
        decimal dd = (decimal)d;
        return dd.ToString("#,##0.00");
      }
    }

    public static int? ParseInt(string IntString)
    {
      if (string.IsNullOrEmpty(IntString))
      {
        return null;
      }
      else
      {
        return Int32.Parse(IntString);
      }
    }

    public static decimal? ParseDecimal(string DecimalString)
    {
      if (string.IsNullOrEmpty(DecimalString))
      {
        return null;
      }
      else
      {
        return decimal.Parse(DecimalString);
      }
    }

    public static bool ParseQueryString(NameValueCollection QueryString, string Parameter, out int Id)
    {
      return Int32.TryParse(QueryString[Parameter], out Id);
    }
  }
  
}